﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using LitJson;

namespace HeerCards
{
    /// <summary>
    /// 一个卡等级域
    /// </summary>
    public class HCLevel
    {
        /// <summary>
        /// 占比的分子
        ///分母为所有HCPool中HCLevel总和加起来的数
        ///例如两个HCLevel，分别为100，200则几率为1/3
        /// </summary>
        internal string GUID { get; set; }

        public int Ratio { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public List<HCCard> Cards { get; set; }

        public bool useImage { get;  set; }
        public bool miniG { get;  set; }
        internal int min;
        internal int max;

        /// <summary>
        /// 默认实例化
        /// </summary>
        /// <param name="ratio">占比位</param>
        public HCLevel(int ratio)
        {
            this.Ratio = ratio;
            this.GUID = Guid.NewGuid().ToString();
            Cards = new List<HCCard>();
        }

        public HCLevel()
        {
        }

        public HCCard getCard()
        {
            List<HCCard> tempList = new List<HCCard>();
            //排布所有卡片
            foreach (HCCard card in Cards.ToArray())
            {
                if (card.ExtraProbability == 0)
                    card.ExtraProbability = 1;
                if (card.ExtraProbability >= 1)
                {
                    for (int i = 0; i < card.ExtraProbability; i++)
                    {
                        var c = card;
                        tempList.Add(c);
                    }
                }
                else
                {
                }
            }
            return tempList[new Random(Guid.NewGuid().GetHashCode()).Next(0, tempList.Count)];
        }

        public void addCard(HCCard Card)
        {
            Cards.Add(Card);
        }

    }


    /// <summary>
    /// 一张卡
    /// </summary>
    public class HCCard : IHCCard
    {
        /// <summary>
        /// 卡片的名字
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 额外几率
        /// </summary>
        public int ExtraProbability { get; set; }

        /// <summary>
        /// 额外几率
        /// </summary>
        public int GUID { get; set; }

        /// <summary>
        /// 图片存放相对路径
        /// </summary>
        public string LocalImagePath { get; set; }

        public HCCard()
        {
            this.GUID = Guid.NewGuid().GetHashCode();
        }

        public HCCard(HCLevel level, string name)
        {
            this.Name = name;
            this.ExtraProbability = 1;
            this.GUID = Guid.NewGuid().GetHashCode();
        }

        public HCCard Clone()
        {
            return new HCCard() { ExtraProbability = ExtraProbability, LocalImagePath = LocalImagePath, Description = Description, Name = Name };
        }
    }

    public interface IHCCard
    {
        /// <summary>
        /// 卡片的名字
        /// </summary>
        string Name { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        string Description { get; set; }

        /// <summary>
        /// 图片存放相对路径
        /// </summary>
        string LocalImagePath { get; set; }
    }
}